<template>
  <!-- 系统账户管理 -->
  <div class="System">
    <!-- 头部查询区域 -->
    <div class="header">
      <!-- 日期选择 -->
      <el-date-picker
        v-model="systemDate"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="timestamp"
      >
      </el-date-picker>
      <!-- 交易类型输入框 -->
      <el-select v-model="systemType" clearable placeholder="请选择类型">
        <el-option label="充值" value="充值"> </el-option>
        <el-option label="收益" value="收益"> </el-option>
        <el-option label="提现" value="提现"> </el-option>
      </el-select>
      <!-- 账单状态下拉框 -->
      <el-select v-model="systemStatus" clearable placeholder="请选择状态">
        <el-option label="正常" value="正常"> </el-option>
        <el-option label="未审核" value="未审核"> </el-option>
      </el-select>
      <!-- 查询按钮 -->
      <el-button type="primary" @click="querysystem">查询</el-button>
    </div>
    <!-- 表格内容展示 -->
    <div class="content">
      <el-table
        :data="systemData"
        stripe
        style="width: 100%"
        v-loading="loading"
      >
        <el-table-column prop="id" label="编号" width="180" align="center">
        </el-table-column>
        <el-table-column
          prop="transferMoney"
          label="交易金额"
          width="180"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="transferTime" label="交易时间" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.transferTime | fmtDate_global }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="交易类型" align="center">
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.status == '正常'">{{
              scope.row.status
            }}</el-tag>
            <el-tag type="info" v-else>{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述" align="center">
        </el-table-column>
      </el-table>
    </div>
    <!-- 底部分页 -->
    <div class="paginetion">
      <!-- 分页组件 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { get, post } from "@/utils/request";

export default {
  data() {
    return {
      systemType: "",
      systemStatus: "",
      systemNumber: "",
      systemDate: "",
      systemData: [],
      currentPage: 1,
      pageSize: 8,
      total: 10,
      systemTime: "",
      systemUserId: [],
      queryData: {},
      loading: true,
    };
  },
  computed: {},
  methods: {
    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.getAllsystemData();

      //console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      //console.log(`当前页: ${val}`);
      this.getAllsystemData();
    },
    // 根据条件模糊查询
    querysystem() {
      let data = {
        beginTime: this.systemDate[0],
        endTime: this.systemDate[1],
        type: this.systemType,
        status: this.systemStatus,
        userId: this.systemNumber,
      };

      for (const key in data) {
        if (!data[key]) {
          delete data[key];
        }
        this.queryData = data;

        this.currentPage = 1;

        this.getAllsystemData();
      }
    },
    // 分页获取所有账单的数据
    async getAllsystemData() {
      let data = {
        page: this.currentPage,
        pageSize: this.pageSize,
      };
      // 发送网络请求
      let res = await get("/account/pageQuerySystemAccount", {
        ...data,
        ...this.queryData,
      });
      setTimeout(() => {
        this.systemData = res.data.list;
      }, 200);
      //console.log(res);
      this.total = res.data.total;
      this.systemUserId = res.data.list.userId;
      this.loading = false;
    },
  },
  //生命周期函数
  created() {
    this.getAllsystemData();
    this.quertsystem();
  },
  mounted() {},
};
</script>
<style scoped>
.header {
  line-height: 40px;
}
.paginetion {
  position: fixed;
  bottom: 40px;
  right: 10px;
}
</style>